<?php
// 定义函数
function sayHello($name) {
    return "你好，$name！";
}

// 调用函数
echo sayHello("李四") . "\n";

// 带默认参数的函数
function calculateArea($length, $width = null) {
    if ($width === null) {
        // 如果只提供一个参数，计算正方形面积
        return $length * $length;
    }
    // 计算矩形面积
    return $length * $width;
}

echo "正方形面积：" . calculateArea(5) . "\n";
echo "矩形面积：" . calculateArea(5, 3) . "\n";

// 可变参数函数
function sum(...$numbers) {
    $total = 0;
    foreach ($numbers as $number) {
        $total += $number;
    }
    return $total;
}

echo "总和：" . sum(1, 2, 3, 4, 5) . "\n";
?>